/// @tags: DP
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

constexpr int MAXN = 5e3 + 3;

int n, d, P;
int C[MAXN][MAXN], f[MAXN][MAXN], sum[MAXN];

inline int main() {
  cin >> n >> d >> P;
  C[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % P;
  }
  f[1][0] = 1, sum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int k = 1; k <= i - 1; ++k) {
      for (int j = 1; j <= i; ++j) {
        f[i][j] = (f[i][j] + (LL)f[i - k][j - 1] * sum[k] % P * C[i - 2][k - 1]) % P;
      }
    }
    for (int j = 0; j < d; ++j) sum[i] = (sum[i] + f[i][j]) % P;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= d; ++j)
      for (int k = 0; k <= d; ++k)
        if (j + k <= d) ans = (ans + (LL)f[i][j] * f[n - i + 1][k]) % P;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= d - 1; ++j)
      for (int k = 0; k <= d - 1; ++k) ans = (ans + P - (LL)f[i][j] * f[n - i][k] % P) % P;
  ans = 2LL * ans * n % P * (n - 1) % P;
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("good.in", "r", stdin);
  freopen("good.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
